package com.hnust.service.impl;

import com.hnust.dao.ReviewInfoDao;
import com.hnust.service.GetReviewInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("GetReviewService")
public class GetReviewServiceImpl implements GetReviewInfoService {

    @Autowired
    private ReviewInfoDao reviewInfoDao;

    //获取各题批阅信息
    public List<Integer> getReviewInfo(String testId, String studentId){
        //获取考生得分字符串
        String reviewInfo = reviewInfoDao.queryReviewInfo(testId,studentId);
        String[] strList = reviewInfo.split("#");

        //按题型分割得分字符串
        //选择题
        String choiceStr = strList[0];
        String[] choice = choiceStr.split("￥");
        //判断题
        String judgeStr = strList[1];
        String[] judge = judgeStr.split("￥");
        //填空题
        String fillStr = strList[2];
        String[] fill = fillStr.split("￥");
        //问答题
        String comprehensiveStr = strList[3];
        String[] comprehensive = comprehensiveStr.split("￥");

        //将所有题目的得分全部放到数组中
        List<Integer> score = new ArrayList<>();
        for (String item:choice){
            score.add(Integer.valueOf(item));
        }
        for (String item:judge) {
            score.add(Integer.valueOf(item));
        }
        for (String item:fill) {
            score.add(Integer.valueOf(item));
        }
        for (String item:comprehensive) {
            score.add(Integer.valueOf(item));
        }

        return score;
    }
}
